package org.example.shop_db.controller;

import org.example.shop_db.pojo.Result;
import org.example.shop_db.pojo.User;
import org.example.shop_db.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/login")
    public Result<User> login(String username, String password) {
        User u = userService.findByName(username);
        if (u == null) {
            //用户未注册
            return Result.error(404,"没有用户");
        }
        if (u.getPassword().equals(password)) {
            //登录成功
            return Result.success(u,"登录成功");

        }else {
            return Result.error(404,"密码错误");
        }

    }
}
